/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}
/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

function setPaymentInfo(isChecked)
{
	with (window.document.frmCheckout) {
		if (isChecked) {
			txtPaymentFirstName.value  = txtShippingFirstName.value;
			txtPaymentLastName.value   = txtShippingLastName.value;
			selPaymentTitle.value	   = selShippingTitle.value;
			txtPaymentAddress.value    = txtShippingAddress.value;
			txtPaymentPhone.value      = txtShippingPhone.value;
			txtPaymentMobile.value     = txtShippingMobile.value;
			txtPaymentEmail.value      = txtShippingEmail.value;			
			txtPaymentState.value      = txtShippingState.value;
			txtPaymentCity.value       = txtShippingCity.value;
			txtPaymentCountry.value	   = txtShippingCountry.value;
			txtPaymentPostalCode.value = txtShippingPostalCode.value;
				
			txtPaymentFirstName.readOnly  = true;
			txtPaymentLastName.readOnly   = true;
			selPaymentTitle.readOnly      = true;
			txtPaymentAddress.readOnly    = true;
			txtPaymentPhone.readOnly      = true;
			txtPaymentMobile.readOnly     = true;
			txtPaymentEmail.readOnly      = true;
			txtPaymentState.readOnly      = true;
			txtPaymentCity.readOnly       = true;
			txtPaymentCountry.readOnly    = true;
			txtPaymentPostalCode.readOnly = true;
		} else {
			txtPaymentFirstName.readOnly  = false;
			txtPaymentLastName.readOnly   = false;
			selPaymentTitle.readOnly      = false;
			txtPaymentAddress.readOnly    = false;
			txtPaymentPhone.readOnly      = false;
			txtPaymentMobile.readOnly     = false;
			txtPaymentEmail.readOnly      = false;
			txtPaymentState.readOnly      = false;
			txtPaymentCity.readOnly       = false;
			txtPaymentCountry.readOnly    = false;
			txtPaymentPostalCode.readOnly = false;
		}
	}
}

function checkShippingAndPaymentInfo()
{
	with (window.document.frmCheckout) {
		if (isEmpty(txtShippingFirstName, 'Enter shipping first name')) {
			return false;
		} else if (isEmpty(txtShippingLastName, 'Enter shipping last name')) {
			return false;
		} else if (isEmpty(txtShippingAddress, 'Enter shipping address')) {
			return false;
		} else if (isEmpty(txtShippingPhone, 'Enter shipping phone number')) {
			return false;
		} else if (isEmpty(txtShippingMobile, 'Enter shipping mobile number')) {
			return false;
		} else if (isEmpty(txtShippingEmail, 'Enter shipping email')){
			return false;
		} else if (isEmpty(txtShippingState, 'Enter shipping province / state')) {
			return false;
		} else if (isEmpty(txtShippingCity, 'Enter shipping city')) {
			return false;
		} else if (isEmpty(txtShippingCountry, 'Enter shipping country')){
			return false;
		} else if (isEmpty(txtShippingPostalCode, 'Enter the shipping address postal/zip code')) {
			return false;
		} else if (isEmpty(txtPaymentFirstName, 'Enter payment first name')) {
			return false;
		} else if (isEmpty(txtPaymentLastName, 'Enter payment last name')) {
			return false;
		} else if (isEmpty(txtPaymentAddress, 'Enter payment shipping address')) {
			return false;
		} else if (isEmpty(txtPaymentPhone, 'Enter payment phone number')) {
			return false;
		} else if (isEmpty(txtPaymentMobile, 'Enter payment mobile number')) {
			return false;
		} else if (isEmpty(txtPaymentEmail, 'Enter payment email')){
			return false;
		} else if (isEmpty(txtPaymentState, 'Enter payment province / state')) {
			return false;
		} else if (isEmpty(txtPaymentCity, 'Enter payment city')) {
			return false;
		} else if (isEmpty(txtPaymentCountry, 'Enter payment country')){
			return false;
		} else if (isEmpty(txtPaymentPostalCode, 'Enter the shipping address postal/zip code')) {
			return false;
		}
	}
}
